package ru.len.cafe.entity.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 * Dish
 * @author Chetvertkov Stanislav
 */
@Entity
public class Dish{

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
	
    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(referencedColumnName="id")
    private List<Ingredient> ingredients;
	
    @JoinColumn(referencedColumnName="id")
    @ManyToOne
    private DishType dishType;
	
    @Column
    private Double price;
	
    /* methods */
    
    public boolean addToIngredients(Ingredient ingredient){
    	if(!this.ingredients.contains(ingredient)){
    		this.ingredients.add(ingredient);
    		return true;
    	}else{
    		return false;
    	}
    }
    
    public boolean addToIngredients(List<Ingredient> ingredients){
    	if(!this.ingredients.containsAll(ingredients)){
    		this.ingredients.addAll(ingredients);
    		return true;
    	}else{
    		return false;
    	}
    }
    
    public boolean removeFromIngredients(Ingredient ingredient){
    	return this.ingredients.remove(ingredient);
    }
    
    public boolean removeFromIngredients(List<Ingredient> ingredients){
    	return this.ingredients.removeAll(ingredients);
    }
    
    /* GETTERS AND SETTERS */
	
    public Long getId() {
	return id;
    }

    public List<Ingredient> getIngredients() {
	return ingredients;
    }

    public void setId(Long id) {
	this.id = id;
    }

    public void setIngredients(List<Ingredient> ingredients) {
	this.ingredients = ingredients;
    }

    public void setPrice(Double price) {
	this.price = price;
    }
	
    public DishType getDishType() {
	return dishType;
    }
    
    public Double getPrice() {
	return price;
    }

    public void setDishType(DishType dishType) {
	this.dishType = dishType;
    }

}
